
https://leetcode.cn/problems/longest-palindromic-substring/
class Solution {
public:

    //中心扩展法
    string longestPalindrome(string s) {
        int n=s.size(),len=0,begin=0;
        for(int i=0;i<n;i++)
        {
            //奇
            int left=i,right=i;
            while(left>=0&&right<n&&s[left]==s[right])
            {
                left--;
                right++;
            }
            //更新最长
            if(right-left-1>len)
            {
                begin=left+1;
                len=right-left-1;
            }

            //偶
            left=i,right=i+1;
            while(left>=0&&right<n&&s[left]==s[right])
            {
                left--;
                right++;
            }
            //更新最长
            if(right-left-1>len)
            {
                begin=left+1;
                len=right-left-1;
            }
        }
        return s.substr(begin,len);
    }
};